// /common/http.api.js
// 此处第二个参数vm，就是我们在页面使用的this，你可以通过vm获取vuex等操作，更多内容详见uView对拦截器的介绍部分：
// https://uviewui.com/js/http.html#%E4%BD%95%E8%B0%93%E8%AF%B7%E6%B1%82%E6%8B%A6%E6%88%AA%EF%BC%9F
import {
	baseURL,
	baseImgUrl
} from '../config/config.js'
import {
	addImgUrl
} from '@/utils/tools.js'
const install = (Vue, vm) => {
	// 此处没有使用传入的params参数
	// /advertising/search
	// VUE_APP_BASE_URL=http://www.cbda1984.com:997
	// VUE_APP_BASR_IMG_URL=http://111.229.30.99:8888/
	// VUE_APP_ROUTER_TIME=30000
	//获取首页轮播图10  活动头部轮播11
	let getBanner = (params = {}) => vm.$u.post('advertising/search', params).then(res => {
		if (res.data.length != 0) {
			res.data[0].imgUrlList = addImgUrl(JSON.parse(res.data[0].imgUrlList), 'imgUrl')
		}
		let arr = addImgUrl(res.data, 'imgUrl')
		return arr
	});
	//热门推荐
	let hotLists = (params = {}) => vm.$u.post('activity/isTopActivity', params).then(res => {
		// titleImg
		let data = addImgUrl(res.data, 'titleImg')
		return data
	})
	// activity/userFindWaitAuditActivityAdmin
	//活动中心
	let activityContent = (params = {}) => vm.$u.post('activity/userFindWaitAuditActivityAdmin', params).then(res => {
		// titleImg
		res.data.list = addImgUrl(res.data.list, 'titleImg')
		return res.data
	})
	//活动详情
	let findActivityById = (params = {}) => vm.$u.post('activity/findActivityById', params).then(res => {
		// titleImg
		res.data.activityTable = addImgUrl(res.data.activityTable, 'titleImg')
		res.data.activityGuestList = addImgUrl(res.data.activityGuestList, 'guestImg')
		res.data.activityTable = addImgUrl(res.data.activityTable, 'activityQrcode')
		res.data.activityTable.startTime = res.data.activityTable.startTime.split(" ")[0]
		res.data.activityTable.endTime = res.data.activityTable.endTime.split(" ")[0]
		res.data.activityTable.applyStartTime = res.data.activityTable.applyStartTime.split(" ")[0]
		res.data.activityTable.applyEndTime = res.data.activityTable.applyEndTime.split(" ")[0]
		return res.data
	})
	//个人档案
	let selectRecordList = (params = {}) => vm.$u.post('award/selectRecordList', params).then(res => {
		// titleImg
		res.data.list = addImgUrl(res.data.list, 'titleImage')
		return res.data
	})
	//企业档案
	let companyRecordList = (params = {}) => vm.$u.post('award/selectRecordList', params).then(res => {
		// titleImg
		res.data.list = addImgUrl(res.data.list, 'titleImage')
		res.data.list.forEach(item => {
			if (item.recodeType) {
				item.recodeType = JSON.parse(item.recodeType)
				item.recodeType = item.recodeType.join('/')
			} else {
				item.recodeType = '无'
			}
		})
		return res.data
	})
	//企业档案详情
	let companyRecordDetails = (params = {}) => vm.$u.post('award/selectRecord', params).then(res => {
		// titleImg
		res.data = addImgUrl(res.data, 'titleImage')
		res.data = addImgUrl(res.data, 'workImg')
		// workImg
		console.log(res.data,'res.data.production')
		// res.data.production = JSON.parse(res.data.production)
		// if (res.data.production) {
		// 	res.data.production.forEach(item => {
		// 		if (item.img) {
		// 			item.img = addImgUrl(item.img, 'url')
		// 		}
		// 	})
		// }

		return res.data
	})
	//个人档案详情
	let selectRecord = (params = {}) => vm.$u.post('award/selectRecord', params).then(res => {
		// titleImg
		res.data = addImgUrl(res.data, 'titleImage')
		res.data.production = JSON.parse(res.data.production)
		if (res.data.production) {
			res.data.production.forEach(item => {
				if (item.img) {
					item.img = addImgUrl(item.img, 'url')
				}
			})
		}

		return res.data
	})
	//作品申报 成果鉴定
	let selectAward = (params = {}) => vm.$u.post('award/selectAward', params).then(res => {
		res.data.list = addImgUrl(res.data.list, 'titleImg')
		return res.data
	})
	// award/selectOneAward
	//作品申报 成果鉴定 --详情
	let selectOneAward = (params = {}) => vm.$u.post('award/selectOneAward', params).then(res => {
		return res.data
	})
	//学习课程
	let findCourseList = (params = {}) => vm.$u.post('course/findCourseList', params).then(res => {
		res.data.list = addImgUrl(res.data.list, 'listImage')
		return res.data
	})
	//学习课程-详情
	let findCourseOne = (params = {}) => vm.$u.post('course/findCourseOne', params).then(res => {
		res.data.course = addImgUrl(res.data.course, 'detailImage')
		return res.data
	})
	//学习课程-查询学习进度
	let findCourseProgressList = (params = {}) => vm.$u.post('course/findCourseProgressList', params).then(res => {
		return res.data
	})
	//学习课程-解锁课程
	let unlockCourseProgress = (params = {}) => vm.$u.post('course/unlockCourseProgress', params).then(res => {
		return res.data
	})
	// course/findClassTableOne
	//学习课程-单个课程查询
	let findClassTableOne = (params = {}) => vm.$u.post('course/findClassTableOne', params).then(res => {
		res.data = addImgUrl(res.data, 'videoUrl')
		return res.data
	})
	//学习课程-完成课程
	let completeCourseProgress = (params = {}) => vm.$u.post('course/completeCourseProgress', params).then(res => {
		return res.data
	})
	//学习课程-查询是否开通课程
	let verificationIsOpenCourse = (params = {}) => vm.$u.post('course/verificationIsOpenCourse', params).then(res => {
		return res.data
	})
	//学习课程-查询是否有证书
	let isGeneratorCertificate = (params = {}) => vm.$u.post('certificate/isGeneratorCertificate', params).then(res => {
		return res.data
	})
	// course/openCourse
	//学习课程-开通课程
	let openCourse = (params = {}) => vm.$u.post('course/openCourse', params).then(res => {
		return res.data
	})
	//学习课程-查询是否有证书邮寄地址
	let findMailingAddress = (params = {}) => vm.$u.post('certificate/findMailingAddress', params).then(res => {
		return res.data
	})
	//学习课程-添加收货地址
	let addMailingAddress = (params = {}) => vm.$u.post('certificate/addMailingAddress', params).then(res => {
		return res.data
	})
	//学习课程-关键字查询证书
	let findCertificate = (params = {}) => vm.$u.post('certificate/findCertificate', params).then(res => {
		if (res.data) {
			res.data = addImgUrl(res.data, 'imgUrl')
		}
		return res.data
	})
	//查询申报表格
	let selectOneAwardDeclare = (params = {}) => vm.$u.post('award/selectOneAwardDeclare', params).then(res => {
		if (res.data.shoolName) {
			res.data.shoolName = JSON.parse(res.data.shoolName).join(',')
		}
		if (res.data.workPerformance) {
			res.data.workPerformance = JSON.parse(res.data.workPerformance)
			res.data.workPerformance.forEach(item => {
				item.img = addImgUrl(item.img, 'url')
			})
		}

		res.data = addImgUrl(res.data, 'productionName')
		res.data = addImgUrl(res.data, 'professionalCategory')

		return res.data
	})
	//查询申报状态
	let selectMyAwardOne = (params = {}) => vm.$u.post('award/selectMyAwardOne', params).then(res => {
		return res.data[0]
	})
	//查询我申报的活动
	let selectMyAward = (params = {}) => vm.$u.post('award/selectMyAward', params).then(res => {
		return res.data
	})
	//查询我参加的活动
	let selectParticipateInActivities = (params = {}) => vm.$u.post('activity/selectParticipateInActivities', params).then(
		res => {
			res.data.list = addImgUrl(res.data.list, 'titleImg')
			return res.data
		})
	//查询我创建的活动
	let userFindWaitAuditActivity = (params = {}) => vm.$u.post('activity/userFindWaitAuditActivity', params).then(
		res => {
			res.data.list = addImgUrl(res.data.list, 'titleImg')
			return res.data
		})
	//查询我参加的活动-详情
	let getSetActivity = (params = {}) => vm.$u.post('activity/findActivityById', params).then(res => {
		res.data.activityTable = addImgUrl(res.data.activityTable, 'titleImg')
		res.data.activityTable = addImgUrl(res.data.activityTable, 'activityQrcode')
		return res.data
	})
	//查询我创建的活动-详情
	let addSetActivity = (params = {}) => vm.$u.post('activity/findActivityById', params).then(res => {
		res.data.activityTable = addImgUrl(res.data.activityTable, 'titleImg')
		res.data.activityGuestList = addImgUrl(res.data.activityGuestList, 'guestImg')
		return res.data
	})
	//查询活动报名数
	let activityTicketRestrict = (params = {}) => vm.$u.post('activity/activityTicketRestrict', params).then(res => {
		return res.data
	})
	// 会议统计票列表
	let activityOfTicketList = (params = {}) => vm.$u.post('activityTicket/activityOfTicketList', params).then(res => {
		return res.data
	})
	//  我的收藏
	let findMyFavorites = (params = {}) => vm.$u.post('favorites/findMyFavorites', params).then(res => {
		return res.data
	})
	//收藏详情
	let selectNewsFIRST = (params = {}) => vm.$u.post('news/selectNewsFIRST', params).then(res => {
		return res.data
	})
	//我的消息
	let findSystemMessageListUser = (params = {}) => vm.$u.post('message/findSystemMessageListUser', params).then(res => {
		return res.data
	})
	//未读信息
	let findUnreadNumber = (params = {}) => vm.$u.post('message/findUnreadNumber', params).then(res => {
		return res.data
	})
	//  标记已读
	let addReadMessage = (params = {}) => vm.$u.post('message/addReadMessage', params).then(res => {
		return res.data
	})
	//  获取发布者信息
	let selectManager = (params = {}) => vm.$u.post('oauth/selectManager', params).then(res => {
		return res.data
	})
	//  查询会员申报状态
	let selectMyVip = (params = {}) => vm.$u.post('vip/selectMyVip', params).then(res => {
		return res.data.list
	})
	// 查询可以申报的vip
	let selectVipList = (params = {}) => vm.$u.post('vip/selectVipList', params).then(res => {
		return res.data.list
	})
	// 
	// 回显存在的申报会员表
	let showVipForm = (params = {}) => vm.$u.post('award/selectOneAwardDeclare', params).then(res => {
		return res.data
	})
	// 提交vip
	let addAwardDeclare = (params = {}) => vm.$u.post('award/addAwardDeclare', params).then(res => {
		return res.data
	})
	// 编辑vip
	let updateAwardDeclaree = (params = {}) => vm.$u.post('award/updateAwardDeclare', params).then(res => {
		return res.data
	})
	//入会须知 
	let selectNotic = (params = {}) => vm.$u.post('notic/selectNotic', params).then(res => {
		return res.data
	})
	//登录
	let login = (params = {}) => vm.$u.post('weChat/weChatLoginActivityApplets', params).then(res => {
		return res.data
	})
	//完善信息
	let updateEssentialInformation = (params = {}) => vm.$u.post('oauth/updateEssentialInformation', params).then(
		res => {
			return res.data
		})
	//获取手机号
	let getPhone = (params = {}) => vm.$u.post('weChat/decodeWeChatAppletsActivity', params).then(
		res => {
			return res.data
		})
	//获取手机号
	let verifyUserInfo = (params = {}) => vm.$u.post('oauth/verifyUserInfo', params).then(
		res => {
			return res.data
		})
	// 支付
	let vipPay = (params = {}) => vm.$u.post('vip/vipPay', params).then(
		res => {
			return res.data
		})
	// 
	// 支付-活动
	let activitySignUpPc = (params = {}) => vm.$u.post('activity/activitySignUpPc', params).then(
		res => {
			return res.data
		})
	// 
	// 活动字符模板
	let activitySignUpField = (params = {}) => vm.$u.post('activity/activitySignUpField', params).then(
		res => {
			return res.data
		})
	// 获取小程序码
	let getPageCode = (params = {}) => vm.$u.post('weChat/generateAppletsActivityPageCode', params).then(
		res => {
			return res.data
		})
	vm.$u.api = {
		getPageCode,
		activitySignUpField,
		activitySignUpPc,
		vipPay,
		verifyUserInfo,
		getPhone,
		updateEssentialInformation,
		login,
		selectNotic,
		updateAwardDeclaree,
		addAwardDeclare,
		showVipForm,
		selectVipList,
		selectMyVip,
		selectManager,
		addReadMessage,
		findUnreadNumber,
		findSystemMessageListUser,
		selectNewsFIRST,
		findMyFavorites,
		activityOfTicketList,
		activityTicketRestrict,
		addSetActivity,
		getSetActivity,
		userFindWaitAuditActivity,
		selectParticipateInActivities,
		selectMyAward,
		selectMyAwardOne,
		selectOneAwardDeclare,
		findCertificate,
		addMailingAddress,
		findMailingAddress,
		openCourse,
		isGeneratorCertificate,
		verificationIsOpenCourse,
		completeCourseProgress,
		findClassTableOne,
		unlockCourseProgress,
		findCourseOne,
		getBanner,
		hotLists,
		activityContent,
		findActivityById,
		selectRecordList,
		selectRecord,
		companyRecordList,
		companyRecordDetails,
		selectAward,
		selectOneAward,
		findCourseList,
		findCourseProgressList
	};
}
export default {
	install
}
